﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Util.Date
{
    public class DateUtility
    {
        private static readonly DateTime UnixTimeStarted = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));

        public static DateTime TimestampToDate(long timestamp)
        {
            TimeSpan span = new TimeSpan(timestamp);
            return UnixTimeStarted.Add(span);
        }

        public static long DateToTimestamp(DateTime time)
        {
            TimeSpan span = time.Subtract(UnixTimeStarted);
            return span.Ticks;
        }

        public static long Get13BitCurrentTimestamp()
        {
            return (DateUtility.DateToTimestamp(DateTime.Now) / 10000);
        }
        public static long Get11BitCurrentTimestamp()
        {
            return (DateUtility.DateToTimestamp(DateTime.Now) / 1000000);
        }

        public static string GetCurrentDate()
        {
            DateTime now = DateTime.Now;
            return (now.Year - 2000) + "-" + string.Format("{0:00}", now.Month) + "-" + string.Format("{0:00}", now.Day);
        }
    }
}
